{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%classpath add mvn org.xerial sqlite-jdbc 3.27.2.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "var conn = BxDriverManager.getConnection(\"jdbc:sqlite:sample.db\");  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "try{  \n",
    "  var sql = \"CREATE TABLE IF NOT EXISTS Person ( id integer PRIMARY KEY,  name text NOT NULL);\";  \n",
    "  var stmt = conn.createStatement();  \n",
    "  var result  = stmt.execute(sql);  \n",
    "  var dbm = conn.getMetaData();\n",
    "  var tables = dbm.getTables(null, null, \"Person\", null);\n",
    "  while (tables.next()) { \n",
    "    var tName = tables.getString(\"TABLE_NAME\");\n",
    "    if (tName != null && tName.equals(\"Person\")) {\n",
    "      System.out.println(\"table '\"+tName+\"' exists \");                  \n",
    "      break;\n",
    "      }\n",
    "  }\n",
    "} catch (Exception e) {  \n",
    "  System.out.println(e.getMessage());  \n",
    "} finally{\n",
    "  conn.close();\n",
    "} "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import java.sql.DriverManager;\n",
    "var conn2 = java.sql.DriverManager.getConnection(\"jdbc:sqlite:sample.db\");"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Java11",
   "language": "java",
   "name": "java"
  },
  "language_info": {
   "codemirror_mode": "text/x-java",
   "file_extension": ".java",
   "mimetype": "",
   "name": "Java",
   "nbconverter_exporter": "",
   "version": "11.0.1-internal"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
